<template>
	<view class="tabs-box" v-if="list.length">
		<view v-for="(item,index) in list" :key="index" :class="tabItemClass(index)" @click="current=index">
			<view class="text">
				{{item}}
			</view>
			<view class="bg"></view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			list: {
				type: Array,
				default () {
					return ['当前周期', '历史周期'];
				}
			},
			value: {
				type: Number,
				default: 0
			}
		},
		data() {
			return {
				current: 0,
			}
		},
		watch: {
			current(current) {
				this.$emit('change', current);
				this.$emit('input', current);
			}
		},
		methods: {
			tabItemClass(index) {
				let res = ['tab-item']
				if (this.current == index) {
					res.push('current')
				}
				return res;
			}
		},
		created() {
			this.current = this.value;
		}
	}
</script>

<style lang="scss">
	.tabs-box {
		display: flex;
		background: #1590ef;
		position: relative;
		padding-top: 10rpx;

		.tab-item {
			flex: 1;
			text-align: center;
			font-size: 28rpx;
			line-height: 76rpx;
			color: #333;
			position: relative;

			&.current {
				color: #1D62BE;

				.bg {
					z-index: 2;
					background-color: #fff;
					box-shadow: 0 0 10rpx rgba(0, 0, 0, .1);
					transform: scale(1.1);
					transform-origin: center 100%;
				}
			}

			.text {
				position: relative;
				z-index: 3;
			}

			.bg {
				position: absolute;
				background-color: #EBF1F9;
				left: 0;
				top: 0;
				right: 0;
				bottom: 0;
				border-radius: 30rpx 30rpx 0 0;
			}
		}
	}
</style>